package com.yunji.cabinet.service.impl;

import com.yunji.base.cache.BaseCache;
import com.yunji.cabinet.cache.CabinetCache;
import com.yunji.cabinet.dao.ICabinetDao;
import com.yunji.cabinet.dao.IMaintainDao;
import com.yunji.cabinet.domain.ContainerDO;
import com.yunji.cabinet.domain.MaintainDO;
import com.yunji.cabinet.params.RecordParam;
import com.yunji.cabinet.vo.MaintainVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Project: yunji-coffee
 * @Package: com.yunji.cabinet.service.impl
 * @Title: MaintainService
 * <p>
 * History:
 * Date                     Version     Author          Summary
 * ============================================================
 * 2024-11-01 15:00:17      V1.0        HuaAo       新建类
 */
@Service
@Slf4j
public class MaintainService {

    @Resource
    IMaintainDao maintainDao;

    @Resource
    ICabinetDao cabinetDao;

    public MaintainDO select(MaintainDO maintain) {
        return maintainDao.select(maintain);
    }

    public boolean create(MaintainDO create) {
        return maintainDao.save(create);
    }

    public boolean update(MaintainDO maintain) {
        return maintainDao.updateById(maintain);
    }

    public List<MaintainVO> searchPageList(RecordParam param) {
        List<MaintainVO> maintainList = maintainDao.searchPageList(param);
        maintainList.stream().forEach(vo -> {
            vo.setSiteName(BaseCache.getSiteName(vo.getSiteId()));
            vo.setAgentName(BaseCache.getAgentName(vo.getAgentId()));
        });
        return maintainList;
    }

    public String getImeiByMaintainCode(String maintainCode) {
        return maintainDao.getImeiByMaintainCode(maintainCode);
    }
}